<?php 
include("function.php");
$start=$_POST['start'];
$end=$_POST['end'];
setcookie("s",$start);
setcookie("e",$end);
mssql_select_db($mssql_database, $conn);
$sql="with dly as
(select A.Number,A.Date,B.bfullname,A.summary,A.Total,0 cash,0 yh,A.Total debt,A.Vchcode,A.etypeid,0 batch
  from Dlyndx A,btype B where A.VchType=11 and A.RedOld like 'F' and (A.draft=2 or A.draft=1 ) and A.btypeid=B.btypeid and A.Date between '$start' and '$end' ) 
  select D.Number,D.Date,D.bfullname,D.summary,D.Total,D.cash,D.yh,D.debt,e.efullname,d.Vchcode,d.etypeid,d.batch  into dzxtt from dly as D
  left join employee E on E.etypeid=D.etypeid;
  merge into dzxt D
using dzxtt E
on(D.Vchcode=E.Vchcode)
when matched then
update set D.Date=E.Date, D.bfullname=E.bfullname,D.summary=E.summary,D.Total=E.Total,D.efullname=E.efullname,D.Vchcode=E.Vchcode,D.etypeid=E.etypeid
when not matched then
insert values(E.Number,E.Date,E.bfullname,E.summary,E.Total,E.cash,E.yh,E.debt,E.efullname,E.Vchcode,E.etypeid,E.batch);
drop table dzxtt
";
$sq=iconv("utf-8",'gbk',"$sql");
$query = mssql_query($sq);
?>
<html>
<head>
    <meta charset="UTF-8"  http-equiv="refresh" content="1; url=index.php">
  
  </head>
  <p>  查询成功！一秒后返回 </p>
  <body>
 

</body>

</html>